package com.awb.securityauth.config;

import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.core.AuthorizationGrantType;
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationGrantAuthenticationToken;

import javax.security.auth.Subject;
import java.util.Map;
import java.util.Set;

/**
 * 密码token
 */
public class OAuth2PasswordAuthenticationToken extends OAuth2AuthorizationGrantAuthenticationToken {

    private final AuthorizationGrantType authorizationGrantType;
    private final Authentication clientPrincipal;
    private final Set<String> scopes;
    private final Map<String, Object> additionalParameters;


    /**
     * Sub-class constructor.
     *
     * @param clientPrincipal      the authenticated client principal
     * @param requestedScopes
     * @param additionalParameters the additional parameters
     */
    protected OAuth2PasswordAuthenticationToken(AuthorizationGrantType authorizationGrantType, Authentication clientPrincipal, Set<String> requestedScopes, Map<String, Object> additionalParameters) {
        
        super(authorizationGrantType, clientPrincipal, additionalParameters);
        this.authorizationGrantType = authorizationGrantType;
        this.clientPrincipal = clientPrincipal;
        this.additionalParameters = additionalParameters;
        this.scopes = requestedScopes;
    }

    @Override
    public boolean implies(Subject subject) {
        return super.implies(subject);
    }
    
    
    

    public AuthorizationGrantType getGrantType() {
        return this.authorizationGrantType;
    }

    @Override
    public Object getPrincipal() {
        return this.clientPrincipal;
    }

    @Override
    public Object getCredentials() {
        return "";
    }

    /**
     * Returns the requested scope(s).
     *
     * @return the requested scope(s), or an empty {@code Set} if not available
     */
    public Set<String> getScopes() {
        return this.scopes;
    }

    /**
     * Returns the additional parameters.
     *
     * @return the additional parameters
     */
    public Map<String, Object> getAdditionalParameters() {
        return this.additionalParameters;
    }


}
